package com.sam.dejian;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class PlatformPreference {
	
	private SharedPreferences sharedPreferences;
	private Editor preferenceEditor;
	private static PlatformPreference self;

	public PlatformPreference(Context context){
		this.sharedPreferences = context.getSharedPreferences(PREFRENCE_NAME, PREFENCE_MODE);
		this.preferenceEditor = this.sharedPreferences.edit();
	}

	private static final String PREFRENCE_NAME = "dejian_platform";
	private static final int PREFENCE_MODE = Context.MODE_PRIVATE;
	private final static String IS_FIRST_RUN = "is_first_run";
	private final static String ACCOUNT = "account";
	private final static String PASSWORD = "password";

	//-----------------------------------------------------------------
	//             GET
	//-----------------------------------------------------------------

	public String getPassword(String defaultValue) {
		return sharedPreferences.getString(PASSWORD, defaultValue);
	}
	public String getAccount(String defaultValue) {
		return sharedPreferences.getString(ACCOUNT, defaultValue);
	}
	//-----------------------------------------------------------------
	//             SET
	//-----------------------------------------------------------------
	public void setAccount(String account){
		preferenceEditor.putString(ACCOUNT,account);
		preferenceEditor.commit();
	}

	public void setPassword(String passwd){
		preferenceEditor.putString(PASSWORD,passwd);
		preferenceEditor.commit();
	}

	public synchronized static PlatformPreference getInstance(Context context){
		if(self == null){
			self = new PlatformPreference(context);
		}
		return self;
	}

	public boolean getIsFirstRun(){
		return sharedPreferences.getBoolean(IS_FIRST_RUN,true);
	}

	public void setIsFirstRun(boolean isFirstRun){
		preferenceEditor.putBoolean(IS_FIRST_RUN,isFirstRun);
		preferenceEditor.commit();
	}

}
